/**
 * @desc
 *
 * @使用场景
 *
 * @author  杨晓东[of1081]
 * @company qianmi.com
 * @Date    16/11/21
 **/
"use strict";
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require("path");

var config = {
  target: "web",
  entry: {
    manager: path.join(__dirname, "./assets/apps/manager/app.js")
  },

  output: {
    path: path.join(__dirname, "./build"),
    filename: "bundle-[name].js",
    chunkFilename: "chunk.[id].[name].js"
  },
  resolve: {
    modulesDirectoires: ["", "web_modules", "node_modules"]
  },
  module: {
    loaders: [
      {
        test: /\.less$/,
        loader: ExtractTextPlugin.extract(
          "style-loader",
          "css-loader!less-loader"
        )
      },
      {
        test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
        loader: "url?limit=10000&mimetype=application/font-woff"
      },
      {
        test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
        loader: "url?limit=10000&mimetype=application/font-woff"
      },
      {
        test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
        loader: "url?limit=10000&mimetype=application/octet-stream"
      },
      { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
      {
        test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
        loader: "url?limit=10000&mimetype=image/svg+xml"
      },
      {
        test: /\.js$/,
        loader: "babel",
        exclude: /(node_modules|bower_components)/,
        query: { presets: ["es2015", "stage-0", "react", "es3"] }
      }
    ]
  },
  externals: {
    // 使用Dll来处理..
    xKit: "xDllContext.xKit",
    iflux: "xDllContext.iflux",
    react: "xDllContext.React",
    scriptjs: "xDllContext.$script",
    immutable: "xDllContext.Immutable",
    "react-dom": "xDllContext.ReactDom",
    "react-addons-pure-render-mixin": "xDllContext.ReactAddons.PureRenderMixin"
  },
  plugins: [
    new webpack.DefinePlugin({
      "process.env.NODE_ENV": JSON.stringify("production"),
      XSite_ENV: JSON.stringify("gray")
    }),
    //new webpack.optimize.OccurrenceOrderPlugin(),
    //new webpack.optimize.UglifyJsPlugin({
    //	compress: {
    //		warnings: false
    //	}
    //}),
    new ExtractTextPlugin("[name]-styles.css")
  ]
};

var compiler = webpack(config);
compiler.run(function(err, stats) {
  if (err) {
    console.error(err);
  } else {
    if (stats.compilation.errors.length > 0) {
      throw stats.compilation.errors;
    }
  }
});
